1. Field of the Invention
Embodiments of the present invention relate to data processing. In particular, methods and systems for sorting data are provided.
2. Background of the Related Art
Computer users often require effective methods of manipulating data. One common type of data manipulation is sorting. The sorting allows users to rearrange data according to predetermined rules and user commands. For example, data items in a list may be arranged in ascending or descending order.
Data sorting may be illustrated with reference to FIG. 1 and FIG. 2. FIG. 1 shows a graphical user interface (GUI) having a pair frames 102 and 104. A first frame 102 contains a plurality of objects on a computer system. A second frame 104 contains a pair of lists 106 associated with an object “Rchasnth”. In the particular implementation shown, a Disk Drive list 108 and a Capacity list 110 are provided. The lists 106 are arranged as a series of columns, wherein each item of each column has a corresponding item in the other column. As such, the lists 108, 110 collectively make up a plurality of rows or records.
A user may elect to sort the items of either list 108, 110 by clicking an appropriate button 112,114. Illustratively, FIG. 1 shows the items of the Disk Drive list 108 sorted alphabetically by name. FIG. 2 shows the Capacity list 110 sorted in descending order.
Methods for sorting lists may be described with reference to “viewable data” and “sortable data”. The viewable data for a particular row and column in a list is the value(s) that is shown/displayed to the user. For example, assume that the file “Gaby5” shown in the Disk Drive list 108 of FIG. 1 has a capacity of 1,572,864 bytes. FIG. 1 shows one viewable data format for this value: 1.5 MB. Other viewable data formats include “1,572,864 bytes”, “1,572,864”, “1572864 bytes”, “1572864”, “1536 KB” and “0.00146 GB”. Accordingly, the viewable data value for a particular value can take any of several forms.
The sortable data for a particular row and column in a list is a value that can be compared to values in other rows of the list in such a way that the list can be sorted based on those values. For some types of data, the viewable data values that are shown in the list column are also sortable data values. Far example, if a column in a list contains filename strings such as “File1”, “File2”, and “File3”, then the list can be sorted in ascending or descending order by filename using these filename strings.
However, the sortable data values for a column are not necessarily the same as the viewable data values that are shown to the user. Consider, for example, the files and associated sizes of Table I.
TABLE I0001File1: 56832 bytes0002File2: 1572864 bytes0003File3: 71782 bytes
Assume that a list showing these files has a “size” column. The viewable data values that are shown to the user in the “size” column for these files might be the string values shown in Table II.
TABLE II0001File1: “55.5 KB”0002File2: “1.5 MB”0003File3: “70.1 KB”
In this case, if the list is sorted by the viewable size values shown in Table II, the files would be shown in the following incorrect order: File2, File1, File3. The correct order is: File1, File3, File2. Accordingly, a method for sorting is needed for cases in which sorting by viewable data values results in incorrect list orders.
One attempt to solve the foregoing problem, is to construct a software environment having a List class and a List/Panel Manager. Such a software environment is illustrated in FIG. 3. A “List” 302 contains the actual list data items 303 (rows). The List 302 provides a first method 304 that allows callers to retrieve the viewable data that is shown to the user for particular list item attributes (columns). For example, if a caller requests the viewable data for a ‘size’ column of an item in the list, the first method 304 retrieves the binary/hexidecimal size value from the list data items 303, converts the value to a string, and returns the string to the caller. Thus, for a binary size value such as 0×00180000, the method 304 might return a string such as “1.5 MB”.
The List 302 also provides a second method 306 that allows callers to sort the list based on the values in any of the list columns. Since the second method 306 is implemented as part of the List 302 that manages the list data items, the second method 306 typically accesses the attributes of the list data items 303 when the list needs to be sorted. For example, if the list is to be sorted based on a ‘size’ value, the second method 306 can access the binary/hexidecimal size values for the list data items 303 so that it can sort the list correctly by size.
A “Panel Manager” 308 presents the list to the user. The Panel Manager 308 handles the user's interaction with the list, such as selecting and performing actions on list items, detecting when the user wants to sort the list on a particular column, etc. The Panel Manager 308 uses the List's first method 304 to get the data that it shows to the user. The Panel Manager 308 uses the List's second method 306 to sort the list on a particular list column.
One problem with the foregoing implementation, is that each type of list (e.g. a file list, a user list, a task list, etc.) implements the functionality defined for the List 302. Thus, each type of list typically implements it's own method for getting the data (the first method 304) and sorting the data (the second method 306). As a result, such sorting environments require multiple implementations of the sorting method 306.
Therefore, there is a need for sorting methods which support sorting of various data formats and preferably reduce the amount of code required.